package com.ruoyi.xst.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xst.domain.Hardware;
import com.ruoyi.xst.service.IHardwareService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 门牌Controller
 * 
 * @author Rambo
 * @date 2024-11-21
 */
@RestController
@RequestMapping("/xst/hardware")
public class HardwareController extends BaseController
{
    @Autowired
    private IHardwareService hardwareService;

    /**
     * 查询门牌列表
     */
    @PreAuthorize("@ss.hasPermi('xst:hardware:list')")
    @GetMapping("/list")
    public TableDataInfo list(Hardware hardware)
    {
        startPage();
        List<Hardware> list = hardwareService.selectHardwareList(hardware);
        return getDataTable(list);
    }

    /**
     * 导出门牌列表
     */
    @PreAuthorize("@ss.hasPermi('xst:hardware:export')")
    @Log(title = "门牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Hardware hardware)
    {
        List<Hardware> list = hardwareService.selectHardwareList(hardware);
        ExcelUtil<Hardware> util = new ExcelUtil<Hardware>(Hardware.class);
        util.exportExcel(response, list, "门牌数据");
    }

    /**
     * 获取门牌详细信息
     */
    @PreAuthorize("@ss.hasPermi('xst:hardware:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hardwareService.selectHardwareById(id));
    }

    /**
     * 新增门牌
     */
    @PreAuthorize("@ss.hasPermi('xst:hardware:add')")
    @Log(title = "门牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Hardware hardware)
    {
        return toAjax(hardwareService.insertHardware(hardware));
    }

    /**
     * 修改门牌
     */
    @PreAuthorize("@ss.hasPermi('xst:hardware:edit')")
    @Log(title = "门牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Hardware hardware)
    {
        return toAjax(hardwareService.updateHardware(hardware));
    }

    /**
     * 删除门牌
     */
    @PreAuthorize("@ss.hasPermi('xst:hardware:remove')")
    @Log(title = "门牌", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hardwareService.deleteHardwareByIds(ids));
    }
}
